﻿using STHPMS1.Common.C_Entity;
using STHPMS1.Common.C_Entity.Stmpms1;
using STHPMS1.ICore;
using STHPMS1.ICore.I_Core;
using STHPMS1.ICore.I_UI;
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Web.Http;
using STHPMS1.Common.C_Extension;
using STHPMS1.Web.W_Model;
using System.Collections.Generic;
using Newtonsoft.Json;
using STHPMS1.Common.C_Utils;
using System.Data;
using System.Reflection;

namespace STHPMS1.Web.W_Controller.Survey
{
    [RoutePrefix("api/S_Evaluate")]
    public class S_EvaluateController : STHPMS1.Web.W_Core.MyController
    {
        #region 评定管理逻辑
        /// <summary>
        /// 默认查询
        /// </summary>
        /// <param name="page"></param>
        /// <param name="rows"></param>
        /// <returns></returns>
        [Route("")]
        [Route("page/{page?}", Name = "GetS_EvaluateByPage")]
        [Route("rows/{rows?}")]
        [Route("page/{page?}/rows/{rows?}")]
        public IHttpActionResult Get(int page = 1, int rows = 10)
        {
            int p = page;
            int s = rows;

            PagingInfo info = new PagingInfo();
            info.PageIndex = p > 0 ? p - 1 : 0;
            info.PageSize = s;
            info.TotalRecords = 0;

            var data = this.Scene.Bll.S_Inspeaccse.Get<S_Inspeaccse>(null, info).ToArray();
            if (data == null) return NotFound();

            var result = new { rows = data, total = info.TotalRecords };

            return Ok(result);
        }

        /// <summary>
        /// 新增评定管理
        /// </summary>
        /// <param name="inspecid"></param>
        /// <param name="date"></param>
        /// <returns></returns>
        [Route("add")]
        public HttpResponseMessage PostSave(string inspecid, string date)
        {
            //查询该评定编号是否存在
            if (this.Scene.Bll.S_Inspeaccse.Exists(inspecid))
            {
                //存在抛出错误
                var response = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent("评定名称已经存在"),
                    ReasonPhrase = "Server Error"
                };
                throw new HttpResponseException(response);
            }
            else
            {
                var newInspc = new S_Inspeaccse()
                {
                    Inspecid = inspecid,
                    Issub = false,
                    Isrddf = false,
                    Isbtstrut = false,
                    Isrutting = false,
                    Isrdpssi = false,
                    Isrdfrc = false,
                    Isrdrgh = false,
                    Isasphalt = false,
                    Iscement = false,
                    Isgravel = false,
                    Isaccess = false,
                    Year_M = date
                };
                this.Scene.Bll.S_Inspeaccse.Save(newInspc);
                var response = Request.CreateResponse(HttpStatusCode.Created);
                // Generate a link to the new book and set the Location header in the response.
                string uri = Url.Link("GetS_EvaluateByPage", new { page = 1 });
                response.Headers.Location = new Uri(uri);

                return response;
            }
        }

        /// <summary>
        /// 生成评定
        /// </summary>
        /// <param name="inspecid"></param>
        /// <returns></returns>
        [Route("Access")]
        public HttpResponseMessage PostAccess(string inspecid)
        {
            try
            {
                //检测是否可以评定?
                this.Scene.Bll.E_Roadwaydetail.Insert(inspecid);
                //更改评定的标志列
                this.Scene.Bll.S_Inspeaccse.UpdateStatus(inspecid, "ISACCESS");
                //清空缓存
                Common.C_Utils.MyCacheTools.ClearAllCache();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            var response = Request.CreateResponse(HttpStatusCode.Created);
            // Generate a link to the new book and set the Location header in the response.
            string uri = Url.Link("GetS_EvaluateByPage", new { page = 1 });
            response.Headers.Location = new Uri(uri);

            return response;
        }

        [Route("")]
        public void Delete(S_Inspeaccse entity)
        {
            string insid = entity.Inspecid;//评定ID
            //检查评定ID是否已经应用于公路技术状况评定明细表
            if (this.Scene.Bll.E_Roadwaydetail.ExistsInspcecId(insid))
            {
                throw new Exception("此批次数据已经生成评定结果，不能删除");
            }
            //删除评定管理
            this.Scene.Bll.S_Inspeaccse.Remove(entity);
            //删除抗滑
            this.Scene.Bll.S_Rdfrc.DelByInspecId(insid);
            //删除平整度
            this.Scene.Bll.S_Rdrgh.DelByInspecId(insid);
            //删除路基
            this.Scene.Bll.S_Subgrd.DelByInspecId(insid);
            //删除沿线设施
            this.Scene.Bll.S_Rddf.DelByInspecId(insid);
            //删除构造物
            this.Scene.Bll.S_Btstrut.DelByInspecId(insid);
            //删除车辙
            this.Scene.Bll.S_Rutting.DelByInspecId(insid);
            //删除结构强度
            this.Scene.Bll.S_Rdpssi.DelByInspecId(insid);
            //删除病害(砂石)
            this.Scene.Bll.S_Pmds_S.DelByInspecId(insid);
            //删除病害(沥青)
            this.Scene.Bll.S_Pmds_Asp.DelByInspecId(insid);
            //删除病害(水泥)
            this.Scene.Bll.S_Pmds_Cem.DelByInspecId(insid);
            //删除评定结果
            this.Scene.Bll.E_Roadwaydetail.Delete(insid);
        }
        #endregion

        #region 文件处理逻辑
        /// <summary>
        /// 上传返回服务器路径
        /// </summary>
        [Route("uploadFile")]
        public void PostUploadFile()
        {
            System.Web.HttpFileCollection hfc = System.Web.HttpContext.Current.Request.Files;
            string uploadPath = System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Upload") + "\\";
            string PhysicalPath = "";
            if (hfc.Count > 0)
            {
                if (!Directory.Exists(uploadPath))
                {
                    Directory.CreateDirectory(uploadPath);
                }
                PhysicalPath = uploadPath + hfc[0].FileName;
                hfc[0].SaveAs(PhysicalPath);
            }

            System.Web.HttpContext.Current.Response.Write(PhysicalPath);
            System.Web.HttpContext.Current.Response.End();
        }

        /// <summary>
        /// 消息提示框数据
        /// </summary>
        /// <param name="inspecid"></param>
        /// <param name="tableName"></param>
        /// <returns></returns>
        [Route("showImportProgress")]
        public IHttpActionResult GetImportProgress(string inspecid, string tableName)
        {
            try
            {
                List<RdClass> lists = new List<RdClass>();
                DataTable dt = this.Scene.Bll.S_Inspeaccse.GetRdway(tableName, inspecid);
                foreach (DataRow dr in dt.Rows)
                {
                    RdClass r = new RdClass();
                    r.Name = dr[0].ToString();
                    //返回上行数据
                    DataTable dtUp = this.Scene.Bll.S_Inspeaccse.GetInspeaccseData(r.Name, inspecid, Common.C_Enum.DirectionEnum.Up11.GetEnumValue(), tableName);
                    if (dtUp.Rows.Count == 1)
                    {
                        UpClass up = new UpClass() { Time = Convert.ToDateTime( dtUp.Rows[0]["SVYDATA"]), Max = dtUp.Rows[0]["MAX"].ToString(), Min = dtUp.Rows[0]["MIN"].ToString() };
                        r.Up = up;
                    }
                    //返回下行数据
                    DataTable dtDown = this.Scene.Bll.S_Inspeaccse.GetInspeaccseData(r.Name, inspecid, Common.C_Enum.DirectionEnum.Down12.GetEnumValue(), tableName);
                    if (dtDown.Rows.Count == 1)
                    {
                        DownClass down = new DownClass() { Time = Convert.ToDateTime(dtDown.Rows[0]["SVYDATA"]), Max = dtDown.Rows[0]["MAX"].ToString(), Min = dtDown.Rows[0]["MIN"].ToString() };
                        r.Down = down;
                    }
                    //返回全幅
                    DataTable dtAll = this.Scene.Bll.S_Inspeaccse.GetInspeaccseData(r.Name, inspecid, Common.C_Enum.DirectionEnum.All13.GetEnumValue(), tableName);
                    if (dtAll.Rows.Count == 1)
                    {
                        AllClass all = new AllClass() { Time = Convert.ToDateTime(dtAll.Rows[0]["SVYDATA"]), Max = dtAll.Rows[0]["MAX"].ToString(), Min = dtAll.Rows[0]["MIN"].ToString() };
                        r.All = all;
                    }
                    //添加到集合
                    lists.Add(r);
                }

                return Ok(JsonConvert.SerializeObject(lists));
            }
            catch (Exception ex)
            {
                //包装错误
                var response = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(ex.Message),
                    ReasonPhrase = "Server Error"
                };
                throw new HttpResponseException(response);
            }
        }
        /// <summary>
        /// 导入数据处理
        /// </summary>
        /// <param name="path">服务器路径</param>
        /// <param name="inspecid">评定名称</param>
        /// <param name="imtType">导入类型</param>
        [Route("saveImport")]
        public IHttpActionResult PostSaveImport(string path, string inspecid, string imtType)
        {
            if (File.Exists(path))
            {
                try
                {
                    //清空缓存
                    Common.C_Utils.MyCacheTools.ClearCache("old");
                    int oldCount = 0;
                    if (Common.C_Enum.ImportTypeEnum.S_Subgrd.GetEnumValue() == int.Parse(imtType)) //路基导入
                    {
                        oldCount = ImportLJ(path, inspecid);
                    }
                    else if (Common.C_Enum.ImportTypeEnum.S_RDDF.GetEnumValue() == int.Parse(imtType)) //沿线设施导入
                    {
                        oldCount = ImportSS(path, inspecid);
                    }
                    else if (Common.C_Enum.ImportTypeEnum.S_Btstrut.GetEnumValue() == int.Parse(imtType)) //桥隧构造物导入
                    {
                        oldCount = ImportQSGZW(path, inspecid);
                    }
                    else if (Common.C_Enum.ImportTypeEnum.S_Rutting.GetEnumValue() == int.Parse(imtType)) //车辙导入
                    {
                        oldCount = ImportCZ(path, inspecid);
                    }
                    else if (Common.C_Enum.ImportTypeEnum.S_Rdfrc.GetEnumValue() == int.Parse(imtType)) //抗滑导入
                    {
                        oldCount = ImportKH(path, inspecid);
                    }
                    else if (Common.C_Enum.ImportTypeEnum.S_Rdrgh.GetEnumValue() == int.Parse(imtType)) //平整度导入
                    {
                        oldCount = ImportPZD(path, inspecid);
                    }
                    else if (Common.C_Enum.ImportTypeEnum.S_Rdpssi.GetEnumValue() == int.Parse(imtType)) //强度导入
                    {
                        oldCount = ImportQD(path, inspecid);
                    }
                    else if (Common.C_Enum.ImportTypeEnum.S_Pmds_Asp.GetEnumValue() == int.Parse(imtType)) //沥青病害导入
                    {
                        oldCount = ImportLQBH(path, inspecid);
                    }
                    else if (Common.C_Enum.ImportTypeEnum.S_PMDS_S.GetEnumValue() == int.Parse(imtType)) //砂石病害导入
                    {
                        oldCount = ImportSSBH(path, inspecid);
                    }
                    else if (Common.C_Enum.ImportTypeEnum.S_Pmds_Cem.GetEnumValue() == int.Parse(imtType)) //水泥病害导入
                    {
                        oldCount = ImportSNBH(path, inspecid);
                    }
                    //向前台输出重复数据
                    return Ok(oldCount);
                }
                catch (Exception ex)
                {
                    File.Delete(path);//删除上传数据
                    //包装错误
                    var response = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                    {
                        Content = new StringContent(ex.Message),
                        ReasonPhrase = "Server Error"
                    };
                    throw new HttpResponseException(response);
                }
            }
            else
            {
                var response = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent("服务器未能保存上传文件"),
                    ReasonPhrase = "Server Error"
                };
                throw new HttpResponseException(response);
            }
        }

        [Route("updateUnit")]
        public IHttpActionResult PostUpdateUnit(string inspecid, string imtType)
        {
            try
            {
                if (Common.C_Utils.MyCacheTools.GetCache("old") != null)
                {
                    //得到表名
                    string tableName = GetTableName(imtType);
                    List<DataRow> old = Common.C_Utils.MyCacheTools.GetCache("old") as List<DataRow>;
                    this.Scene.Bll.S_Inspeaccse.UpdateUnit(tableName, old, inspecid);
                    //删除指定评定中的重复检测数据
                    Common.C_Utils.MyCacheTools.ClearCache("old");
                }
                return Ok("");
            }
            catch (Exception ex)
            {
                var response = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(ex.Message),
                    ReasonPhrase = "Server Error"
                };
                throw new HttpResponseException(response);
            }

        }

        /// <summary>
        /// 从枚举中得到表名
        /// </summary>
        /// <param name="imtType"></param>
        /// <returns></returns>
        private string GetTableName(string imtType)
        {
            if (Common.C_Enum.ImportTypeEnum.S_Subgrd.GetEnumValue() == int.Parse(imtType))
            {
                return Common.C_Enum.ImportTypeEnum.S_Subgrd.ToString();
            }
            else if (Common.C_Enum.ImportTypeEnum.S_Btstrut.GetEnumValue() == int.Parse(imtType))
            {
                return Common.C_Enum.ImportTypeEnum.S_Btstrut.ToString();
            }
            else if (Common.C_Enum.ImportTypeEnum.S_Pmds_Asp.GetEnumValue() == int.Parse(imtType))
            {
                return Common.C_Enum.ImportTypeEnum.S_Pmds_Asp.ToString();
            }
            else if (Common.C_Enum.ImportTypeEnum.S_Pmds_Cem.GetEnumValue() == int.Parse(imtType))
            {
                return Common.C_Enum.ImportTypeEnum.S_Pmds_Cem.ToString();
            }
            else if (Common.C_Enum.ImportTypeEnum.S_PMDS_S.GetEnumValue() == int.Parse(imtType))
            {
                return Common.C_Enum.ImportTypeEnum.S_PMDS_S.ToString();
            }
            else if (Common.C_Enum.ImportTypeEnum.S_RDDF.GetEnumValue() == int.Parse(imtType))
            {
                return Common.C_Enum.ImportTypeEnum.S_RDDF.ToString();
            }
            else if (Common.C_Enum.ImportTypeEnum.S_Rdfrc.GetEnumValue() == int.Parse(imtType))
            {
                return Common.C_Enum.ImportTypeEnum.S_Rdfrc.ToString();
            }
            else if (Common.C_Enum.ImportTypeEnum.S_Rdpssi.GetEnumValue() == int.Parse(imtType))
            {
                return Common.C_Enum.ImportTypeEnum.S_Rdpssi.ToString();
            }
            else if (Common.C_Enum.ImportTypeEnum.S_Rdrgh.GetEnumValue() == int.Parse(imtType))
            {
                return Common.C_Enum.ImportTypeEnum.S_Rdrgh.ToString();
            }
            else if (Common.C_Enum.ImportTypeEnum.S_Rutting.GetEnumValue() == int.Parse(imtType))
            {
                return Common.C_Enum.ImportTypeEnum.S_Rutting.ToString();
            }
            return "";
        }

        #region 公共方法
        /// <summary>
        /// 反射获取对象的所有属性
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        private PropertyInfo[] GetAllProperty(object t)
        {
            Type temp = t.GetType();
            return temp.GetProperties();
        }

        /// <summary>
        /// 模糊匹配单元，获取起终位置和单元编号
        /// </summary>
        /// <param name="b_unitList"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="unit"></param> 
        private void Matching(List<B_Unit> b_unitList, ref double start, ref double end, ref string unit, ref string name)
        {
            List<string> units = new List<string>();//记录被匹配的单元，防止重复匹配
            if (b_unitList.Count > 0)
            {
                foreach (B_Unit b in b_unitList)
                {
                    if (System.Math.Abs(start - b.Beginmp) < 500) //默认导入数据以500米为合计一个单元
                    {
                        if (!units.Contains(b.Unit))
                        {
                            start = b.Beginmp;
                            end = b.Endmp;
                            unit = b.Unit;
                            name = b.Name;
                            units.Add(b.Unit);//保存
                            break;
                        }
                        else
                        {
                            throw new Exception("系统单元已经被匹配,单元桩号:" + b.Beginmp + "  导入桩号:" + start);
                        }
                    }
                }
                if (unit == "")
                {
                    throw new Exception("导入数据未能找到匹配桩号,起终点桩号:" + start + "--" + end);
                }
            }
            else
            {
                throw new Exception("此路线未划分路段,没有桩号");
            }
        }

        private void TestCheckData(DataTable dt)
        {
            List<string> o = new List<string>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                o.Add(dt.Rows[i][0].ToString());
                DataRow fstdr = dt.Rows[i];//第1行
                for (int j = i + 1; j < dt.Rows.Count; j++)
                {
                    DataRow secdr = dt.Rows[j]; //第2行
                    if (fstdr[0].ToString() == secdr[0].ToString() && fstdr[1].ToString() == secdr[1].ToString())
                    {
                        if (fstdr[5].ToString() == secdr[5].ToString())
                        {
                            o.Add(string.Format("主键{3}冲突:路线{0},方向{1},行数{2}", fstdr[4].ToString(), fstdr[5].ToString(), i, fstdr[0].ToString()));
                            o.Add(string.Format("主键{3}冲突:路线{0},方向{1},行数{2}", secdr[4].ToString(), secdr[5].ToString(), j, secdr[0].ToString()));
                            //string msg = string.Format("主键{4}冲突:路线{0},方向{1},行数{2} vs {3}", fstdr[4].ToString(), fstdr[5].ToString(), i, j, fstdr[0].ToString());
                            //throw new Exception(msg);
                        }
                    }
                }
            }

            string msg = "";
            foreach (string s in o)
            {
                msg += o;
            }
            if (msg != "") throw new Exception(msg);
        }

        /// <summary>
        /// 检测Excel起终点桩号是否重复
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="start">列起点索引</param>
        /// <param name="end">列终点索引</param>
        /// <param name="timeColumn">列调查日期索引</param>
        private void CheckDatatable(DataTable dt, int startColumn, int endColumn, int timeColumn)
        {
            //List<int> samerow=new List<int>();
            //int flag = 0;
            //List<DataRow> listdr = new List<DataRow>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow fstdr = dt.Rows[i];//第1行
                for (int j = i + 1; j < dt.Rows.Count; j++)
                {
                    DataRow secdr = dt.Rows[j]; //第2行
                    if (fstdr[timeColumn].ToString() == secdr[timeColumn].ToString()) //日期一样
                    {
                        if (fstdr[startColumn].ToString() == secdr[startColumn].ToString() || fstdr[endColumn].ToString() == secdr[endColumn].ToString()) //如果相同
                        {
                            if (fstdr[dt.Columns.Count - 1].ToString() == secdr[dt.Columns.Count - 1].ToString())//同一方向
                            {
                                if (fstdr[0].ToString() == secdr[0].ToString()) //同一线路
                                {
                                    string msg = string.Format("线路{0}在{1}的数据起点或终点桩号重复", fstdr[0].ToString(), fstdr[timeColumn].ToString());
                                    throw new Exception(msg);//同一线路
                                }

                            }

                        }
                    }
                    //for (int k = 0; k < dt.Columns.Count; k++)
                    //{
                    //    if (dr[k].ToString() == secdr[k].ToString())
                    //        flag++;
                    //    if (flag == dt.Columns.Count)
                    //        samerow.Add(j);
                    //}
                    //flag = 0;
                }
            }
            //IEnumerable<int> sameindex = samerow.Distinct();
            //foreach (var item in sameindex)
            //{
            //    listdr.Add(dt.Rows[item]);//记录dt中重复行
            //}
            //foreach (var item in listdr)
            //{
            //    dt.Rows.Remove(item);//移除dt中重复行
            //}
            //return dt;
        }
        #endregion

        #region 路基数据处理方法
        /// <summary>
        /// 获取路基导入数据
        /// </summary>
        /// <param name="excel"></param>
        /// <param name="inspecid"></param>
        /// <param name="startRow"></param>
        /// <param name="oldUnit"></param>
        /// <returns></returns>
        private DataTable GetLJData_New(DataTable excel, string inspecid, int startRow, List<DataRow> oldUnit)
        {
            DataTable kh = new DataTable();
            PropertyInfo[] propertys = GetAllProperty(new S_Subgrd()); //路基
            foreach (PropertyInfo p in propertys)
            {
                kh.Columns.Add(new DataColumn(p.Name.ToUpper()));
            }
            kh.Columns.Add(new DataColumn("index")); //记录错误行号
            if (excel.Rows.Count == 0)
            {
                throw new Exception("Excel没有数据");
            }
            int index = startRow + 1;

            Dictionary<string, List<B_Unit>> temp = new Dictionary<string, List<B_Unit>>();
            CheckDatatable(excel, 1, 2, 3);
            List<string> keys = new List<string>();
            //遍历DataTable(路线,起终桩号等数据,方向)
            foreach (DataRow r in excel.Rows)
            {
                //查询该线路该方向的的所有单元
                double _start = Convert.ToDouble(r[1]);//起点桩号
                double _end = Convert.ToDouble(r[2]);//结束桩号

                string _rdid = r[0].ToString();//路线编号
                string _dir = getDir(r[excel.Columns.Count - 1].ToString());//方向
                //该线路该方向下的所有单元

                List<B_Unit> b_unitList = GetCacheUnit(_rdid, _dir);

                //单元名称
                string _name = "";
                //查找单元
                string _unit = "";
                //模糊匹配单元
                Matching(b_unitList, ref _start, ref _end, ref _unit, ref _name);
                //查询该单元是否已经有今年的评定数据
                string _SVYDATA = r[3].ToString();//调查日期
                //过滤重复单元
                if (!keys.Contains(_unit + "#" + _dir))
                {
                    keys.Add(_unit + "#" + _dir);
                }
                else
                {
                    continue;
                }
                string _insid = inspecid;//评定ID
                string _surveyer = r[4].ToString();//检测人员
                string _PMWID = r[5].ToString();//路面宽度
                string _SLDDHIM = r[6].ToString();//路肩沟不洁
                string _SLDDG_L = r[7].ToString();//路肩损坏l
                string _SLDDG_H = r[8].ToString();//路肩损坏h
                string _SLPCP_L = r[9].ToString();//边坡坍塌l
                string _SLPCP_M = r[10].ToString();//边坡坍塌m
                string _SLPCP_H = r[11].ToString();//边坡坍塌h
                string _WATGUY_L = r[12].ToString();//水毁冲沟l
                string _WATGUY_M = r[13].ToString();//水毁冲沟m
                string _WATGUY_H = r[14].ToString();//水毁冲沟m
                string _DASUGCT_L = r[15].ToString();//路基构造物损坏l
                string _DASUGCT_M = r[16].ToString();//路基构造物损坏m
                string _DASUGCT_H = r[17].ToString();//路基构造物损坏h
                string _CUBDAMG = r[18].ToString();//路缘石损坏
                string _SUBSLT_L = r[19].ToString();//路基沉降l
                string _SUBSLT_M = r[20].ToString();//路基沉降m
                string _SUBSLT_H = r[21].ToString();//路基沉降h
                string _DRSYST_L = r[22].ToString();//排水系统淤塞l
                string _DRSYST_H = r[23].ToString();//排水系统淤塞h
                string _importdate = DateTime.Now.ToShortDateString();//导入时间

                DataRow dr = kh.NewRow();
                dr["UNIT"] = _unit;
                dr["SVYDATA"] = _SVYDATA;
                dr["RDWAYID"] = _rdid;
                dr["DIRECTION_DICTID"] = _dir;
                dr["HIS_VERSION"] = GetVersion(_rdid);
                dr["NAME"] = _name;
                dr["INSPECID"] = _insid;
                dr["SVYPS"] = _surveyer;
                dr["PMWID"] = _PMWID;
                dr["SLDDHIM"] = _SLDDHIM == "" ? "0" : _SLDDHIM;
                dr["SLDDG_L"] = _SLDDG_L == "" ? "0" : _SLDDG_L;
                dr["SLDDG_H"] = _SLDDG_H == "" ? "0" : _SLDDG_H;
                dr["SLPCP_L"] = _SLPCP_L == "" ? "0" : _SLPCP_L;
                dr["SLPCP_M"] = _SLPCP_M == "" ? "0" : _SLPCP_M;
                dr["SLPCP_H"] = _SLPCP_H == "" ? "0" : _SLPCP_H;
                dr["WATGUY_L"] = _WATGUY_L == "" ? "0" : _WATGUY_L;
                dr["WATGUY_M"] = _WATGUY_M == "" ? "0" : _WATGUY_M;
                dr["WATGUY_H"] = _WATGUY_H == "" ? "0" : _WATGUY_H;
                dr["DASUGCT_L"] = _DASUGCT_L == "" ? "0" : _DASUGCT_L;
                dr["DASUGCT_M"] = _DASUGCT_M == "" ? "0" : _DASUGCT_M;
                dr["DASUGCT_M"] = _DASUGCT_H == "" ? "0" : _DASUGCT_H;
                dr["CUBDAMG"] = _CUBDAMG == "" ? "0" : _CUBDAMG;
                dr["SUBSLT_L"] = _SUBSLT_L == "" ? "0" : _SUBSLT_L;
                dr["SUBSLT_M"] = _SUBSLT_M == "" ? "0" : _SUBSLT_M;
                dr["SUBSLT_H"] = _SUBSLT_H == "" ? "0" : _SUBSLT_H;
                dr["DRSYST_L"] = _DRSYST_L == "" ? "0" : _DRSYST_L;
                dr["DRSYST_H"] = _DRSYST_H == "" ? "0" : _DRSYST_H;
                dr["IMPORTDATE"] = _importdate;
                dr["index"] = index++;
                

                //检查是否有该批次最新的重复评定数据
               // string oldSVYDATA = this.Scene.Bll.S_Inspeaccse.Exists(_unit, inspecid, "S_Subgrd"); //this.Scene.Bll.S_Subgrd.Exists(_unit, inspecid);
                //检查是否有该批次的重复评定数据
                if (this.Scene.Bll.S_Inspeaccse.Exists(_unit, inspecid, "S_Subgrd", _SVYDATA))
                {

                    oldUnit.Add(dr);
                    continue;
                } 
                kh.Rows.Add(dr);
            }
            return kh;
        }

        private int ImportLJ(string path, string inspecid)
        {
            List<DataRow> oldUnit = new List<DataRow>();//保存重复的unit
            int startRow = 1;
            DataTable excel = Common.C_Excel.ExcelTool.GetDataTableFromExcel(path, startRow);
            DataTable entity = GetLJData_New(excel, inspecid, startRow, oldUnit);
            Excel_BaseImportData exData = new Excel_BaseImportData(new S_Subgrd());//路基
            exData.DtSource = entity;
            exData.TableName = "S_Subgrd"; //路基
            this.Scene.Bll.Excel.ImportData(exData);
            //更改评定的路基列
            this.Scene.Bll.S_Inspeaccse.UpdateStatus(inspecid, "ISSUB");
            //将重复的unit保存到缓存
            if (oldUnit.Count > 0)
            {
                Common.C_Utils.MyCacheTools.SetCache("old", oldUnit, 24);//保存到缓存
            }
            return oldUnit.Count;
        }
        #endregion

        #region 沿线设施处理方法
        private DataTable GetSSData_New(DataTable excel, string inspecid, int startRow, List<DataRow> oldUnit)
        {
            DataTable kh = new DataTable();
            PropertyInfo[] propertys = GetAllProperty(new S_Rddf());//沿线设施
            foreach (PropertyInfo p in propertys)
            {
                kh.Columns.Add(new DataColumn(p.Name.ToUpper()));
            }
            kh.Columns.Add(new DataColumn("index")); //记录错误行号
            if (excel.Rows.Count == 0)
            {
                throw new Exception("Excel没有数据");
            }
            int index = startRow + 1;
            Dictionary<string, List<B_Unit>> temp = new Dictionary<string, List<B_Unit>>();
            CheckDatatable(excel, 1, 2, 3);
            List<string> keys = new List<string>();
            foreach (DataRow r in excel.Rows)
            {
                double _start = Convert.ToDouble(r[1]);//起点桩号
                double _end = Convert.ToDouble(r[2]);//结束桩号

                string _rdid = r[0].ToString();//路线编号
                string _dir = getDir(r[excel.Columns.Count - 1].ToString());//方向
                //该线路该方向下的所有单元

                List<B_Unit> b_unitList = GetCacheUnit(_rdid, _dir);

                string _unit = "";
                string _name = "";
                //模糊匹配单元
                Matching(b_unitList, ref _start, ref _end, ref _unit, ref _name);

                string _SVYDATA = r[3].ToString();//调查日期
                //过滤重复单元
                if (!keys.Contains(_unit + "#" + _dir))
                {
                    keys.Add(_unit + "#" + _dir);
                }
                else
                {
                    continue;
                }
                string _insid = inspecid;//评定ID
                string _surveyer = r[4].ToString();//检测人员
                string _PMWID = r[5].ToString();//路面宽度
                string _PTFLDF_L = r[6].ToString();//设施缺损轻
                string _PTFLDF_H = r[7].ToString();//设施缺损重
                string _ISGTDMG = r[8].ToString();//隔离栅损坏
                string _MKDEFT = r[9].ToString();//标志缺损
                string _INDEFT = r[10].ToString();//标线缺损
                string _AFMNGPR = r[11].ToString();//绿化管护               
                string _importdate = DateTime.Now.ToShortDateString();//导入时间
                DataRow dr = kh.NewRow();
                dr["UNIT"] = _unit;
                dr["SVYDATA"] = _SVYDATA;
                dr["RDWAYID"] = _rdid;
                dr["DIRECTION_DICTID"] = _dir;
                dr["HIS_VERSION"] = GetVersion(_rdid);
                dr["NAME"] = _name;
                dr["INSPECID"] = _insid;
                dr["SVYPS"] = _surveyer;
                dr["PMWID"] = _PMWID;
                dr["PTFLDF_L"] = _PTFLDF_L;
                dr["PTFLDF_H"] = _PTFLDF_H;
                dr["ISGTDMG"] = _ISGTDMG;
                dr["MKDEFT"] = _MKDEFT;
                dr["INDEFT"] = _INDEFT;
                dr["AFMNGPR"] = _AFMNGPR;
                dr["IMPORTDATE"] = _importdate;
                dr["index"] = index++;
               

                //检查是否有该批次最新的重复评定数据
                //string oldSVYDATA = this.Scene.Bll.S_Inspeaccse.Exists(_unit, inspecid, "S_Rddf"); ;// this.Scene.Bll.S_Rddf.Exists(_unit, inspecid);
                //检查是否有该批次的重复评定数据
                if (this.Scene.Bll.S_Inspeaccse.Exists(_unit, inspecid, "S_Rddf", _SVYDATA))
                {

                    oldUnit.Add(dr);
                    continue;
                }  
                kh.Rows.Add(dr);
            }
            return kh;
        }


        private int ImportSS(string path, string inspecid)
        {
            List<DataRow> oldUnit = new List<DataRow>();//保存重复的unit
            int startRow = 1;
            DataTable excel = Common.C_Excel.ExcelTool.GetDataTableFromExcel(path, startRow);
            DataTable entity = GetSSData_New(excel, inspecid, startRow, oldUnit);
            Excel_BaseImportData exData = new Excel_BaseImportData(new S_Rddf());//设施
            exData.DtSource = entity;
            exData.TableName = "S_Rddf"; //沿线设施
            this.Scene.Bll.Excel.ImportData(exData);
            //更改评定的路基列
            this.Scene.Bll.S_Inspeaccse.UpdateStatus(inspecid, "ISRDDF");
            //将重复的unit保存到缓存
            if (oldUnit.Count > 0)
            {
                Common.C_Utils.MyCacheTools.SetCache("old", oldUnit, 24);//保存到缓存
            }
            return oldUnit.Count;
        }
        #endregion

        #region 桥隧构造物处理方法
        private DataTable GetQSGZWData_New(DataTable excel, string inspecid, int startRow, List<DataRow> oldUnit)
        {
            DataTable kh = new DataTable();
            PropertyInfo[] propertys = GetAllProperty(new S_Btstrut());
            foreach (PropertyInfo p in propertys)
            {
                kh.Columns.Add(new DataColumn(p.Name.ToUpper()));
            }
            kh.Columns.Add(new DataColumn("index")); //记录错误行号
            if (excel.Rows.Count == 0)
            {
                throw new Exception("Excel没有数据");
            }
            Dictionary<string, List<B_Unit>> temp = new Dictionary<string, List<B_Unit>>();
            CheckDatatable(excel, 1, 2, 3);
            int index = startRow + 1;

            List<string> keys = new List<string>();
            foreach (DataRow r in excel.Rows)
            {
                double _start = Convert.ToDouble(r[1]);//起点桩号
                double _end = Convert.ToDouble(r[2]);//结束桩号
                string _rdid = r[0].ToString();//路线编号
                string _dir = getDir(r[excel.Columns.Count - 1].ToString());//方向
                //该线路该方向下的所有单元

                List<B_Unit> b_unitList = GetCacheUnit(_rdid, _dir);

                string _unit = "";
                string _name = "";
                //模糊匹配单元
                Matching(b_unitList, ref _start, ref _end, ref _unit, ref _name);

                string _SVYDATA = r[3].ToString();//调查日期
                //过滤重复单元
                if (!keys.Contains(_unit + "#" + _dir))
                {
                    keys.Add(_unit + "#" + _dir);
                }
                else
                {
                    continue;
                }
                string _insid = inspecid;//评定ID
                string _surveyer = r[4].ToString();//检测人员
                string _PMWID = r[5].ToString();//路面宽度
                string _BDTC_OT = r[6].ToString();//桥梁1，2
                string _BDTC_THR = r[7].ToString();//桥梁3
                string _BDTC_FU = r[8].ToString();//桥梁4
                string _BDTC_FV = r[9].ToString();//桥梁5
                string _TUNL_N = r[10].ToString();//隧道技术状况1
                string _TUNL_A = r[11].ToString();//隧道技术状况2
                string _TUNL_D = r[12].ToString();//隧道技术状况3
                string _CLVT_F = r[13].ToString();//涵洞技术状况1
                string _CLVT_LP = r[14].ToString();//涵洞技术状况2
                string _CLVT_P = r[15].ToString();//涵洞技术状况3
                string _CLVT_D = r[16].ToString();//涵洞技术状况4
                string _importdate = DateTime.Now.ToShortDateString();//导入时间
                DataRow dr = kh.NewRow();
                dr["UNIT"] = _unit;
                dr["SVYDATA"] = _SVYDATA;
                dr["RDWAYID"] = _rdid;
                dr["DIRECTION_DICTID"] = _dir;
                dr["HIS_VERSION"] = GetVersion(_rdid);
                dr["INSPECID"] = _insid;
                dr["NAME"] = _name;
                dr["SVYPS"] = _surveyer;
                dr["PMWID"] = _PMWID;
                dr["BDTC_OT"] = _BDTC_OT;
                dr["BDTC_THR"] = _BDTC_THR;
                dr["BDTC_FU"] = _BDTC_FU;
                dr["BDTC_FV"] = _BDTC_FV;
                dr["TUNL_N"] = _TUNL_N;
                dr["TUNL_A"] = _TUNL_A;
                dr["TUNL_D"] = _TUNL_D;
                dr["CLVT_F"] = _CLVT_F;
                dr["CLVT_LP"] = _CLVT_LP;
                dr["CLVT_P"] = _CLVT_P;
                dr["CLVT_D"] = _CLVT_D;
                dr["IMPORTDATE"] = _importdate;
                dr["index"] = index++;
               
                //检查是否有该批次最新的重复评定数据
                //string oldSVYDATA = this.Scene.Bll.S_Inspeaccse.Exists(_unit, inspecid, "S_Btstrut"); // this.Scene.Bll.S_Btstrut.Exists(_unit, inspecid);
                //检查是否有该批次的重复评定数据
                if (this.Scene.Bll.S_Inspeaccse.Exists(_unit, inspecid, "S_Btstrut", _SVYDATA))
                {

                    oldUnit.Add(dr);
                    continue;
                }  
                kh.Rows.Add(dr);
            }
            return kh;
        }

        private int ImportQSGZW(string path, string inspecid)
        {
            List<DataRow> oldUnit = new List<DataRow>();//保存重复的unit
            int startRow = 1;
            DataTable excel = Common.C_Excel.ExcelTool.GetDataTableFromExcel(path, startRow);
            DataTable entity = GetQSGZWData_New(excel, inspecid, startRow, oldUnit);
            Excel_BaseImportData exData = new Excel_BaseImportData(new S_Btstrut());//桥隧构造物
            exData.DtSource = entity;
            exData.TableName = "S_Btstrut"; //桥隧构造物
            this.Scene.Bll.Excel.ImportData(exData);
            //更改评定的路基列
            this.Scene.Bll.S_Inspeaccse.UpdateStatus(inspecid, "ISBTSTRUT");
            //将重复的unit保存到缓存
            if (oldUnit.Count > 0)
            {
                Common.C_Utils.MyCacheTools.SetCache("old", oldUnit, 24);//保存到缓存
            }
            return oldUnit.Count;
        }
        #endregion

        #region 车辙处理方法
        private DataTable GetCZData_New(DataTable excel, string inspecid, int startRow, List<DataRow> oldUnit)
        {
            DataTable kh = new DataTable();
            PropertyInfo[] propertys = GetAllProperty(new S_Rutting());
            foreach (PropertyInfo p in propertys)
            {
                kh.Columns.Add(new DataColumn(p.Name.ToUpper()));
            }
            kh.Columns.Add(new DataColumn("index")); //记录错误行号
            if (excel.Rows.Count == 0)
            {
                throw new Exception("Excel没有数据");
            }
            Dictionary<string, List<B_Unit>> temp = new Dictionary<string, List<B_Unit>>();
            CheckDatatable(excel, 1, 2, 3);
            int index = startRow + 1;

            List<string> keys = new List<string>();
            foreach (DataRow r in excel.Rows)
            {
                double _start = Convert.ToDouble(r[1]);//起点桩号
                double _end = Convert.ToDouble(r[2]);//结束桩号
                string _rdid = r[0].ToString();//路线编号
                string _dir = getDir(r[excel.Columns.Count - 1].ToString());//方向
                //该线路该方向下的所有单元

                List<B_Unit> b_unitList = GetCacheUnit(_rdid, _dir);// GetCacheUnit(_rdid, _dir);

                string _unit = "";


                string _name = "";
                //模糊匹配单元
                Matching(b_unitList, ref _start, ref _end, ref _unit, ref _name);

                string _svydata = r[3].ToString();//调查日期
                //过滤重复单元
                if (!keys.Contains(_unit + "#" + _dir))
                {
                    keys.Add(_unit + "#" + _dir);
                }
                else
                {
                    continue;
                }
                string _device = r[4].ToString();//检测设备
                string _insid = inspecid;//评定ID
                string _surveyer = r[5].ToString();//检测人员
                string _RUT_LN1 = r[6].ToString();//外道车辙
                string _RUT_LN2 = r[7].ToString();//内道车辙
                string _RD = r[8].ToString();//RD
                string _comments = r[9].ToString();//备注
                string _importdate = DateTime.Now.ToShortDateString();//导入时间
                DataRow dr = kh.NewRow();
                dr["UNIT"] = _unit;
                dr["SVYDATA"] = _svydata;
                dr["NAME"] = _name;
                dr["RDWAYID"] = _rdid;
                dr["DIRECTION_DICTID"] = _dir;
                dr["HIS_VERSION"] = GetVersion(_rdid);
                dr["DEVICE"] = _device;
                dr["INSPECID"] = _insid;
                dr["SURVEYER"] = _surveyer;
                dr["RD"] = _RD;
                dr["RUT_LN1"] = _RUT_LN1;
                dr["RUT_LN2"] = _RUT_LN2;
                dr["COMMENTS"] = _comments;
                dr["IMPORTDATE"] = _importdate;
                dr["index"] = index++;
               
                //检查是否有该批次最新的重复评定数据
                //string oldSVYDATA = this.Scene.Bll.S_Inspeaccse.Exists(_unit, inspecid, "S_Rutting");// this.Scene.Bll.S_Rutting.Exists(_unit, inspecid);
                //检查是否有该批次的重复评定数据
                if (this.Scene.Bll.S_Inspeaccse.Exists(_unit, inspecid, "S_Rutting", _svydata))
                {
                    oldUnit.Add(dr);
                    continue;
                }  
                kh.Rows.Add(dr);
            }
            return kh;
        }

        private int ImportCZ(string path, string inspecid)
        {
            List<DataRow> oldUnit = new List<DataRow>();//保存重复的unit
            int startRow = 0;
            DataTable excel = Common.C_Excel.ExcelTool.GetDataTableFromExcel(path, startRow);
            DataTable entity = GetCZData_New(excel, inspecid, startRow, oldUnit);
            Excel_BaseImportData exData = new Excel_BaseImportData(new S_Rutting());//桥隧构造物
            exData.DtSource = entity;
            exData.TableName = "S_Rutting"; //桥隧构造物
            this.Scene.Bll.Excel.ImportData(exData);
            //更改评定的路基列
            this.Scene.Bll.S_Inspeaccse.UpdateStatus(inspecid, "ISRUTTING");
            //将重复的unit保存到缓存
            if (oldUnit.Count > 0)
            {
                Common.C_Utils.MyCacheTools.SetCache("old", oldUnit, 24);//保存到缓存
            }
            return oldUnit.Count;
        }
        #endregion

        #region 抗滑处理方法
        private DataTable GetKHData_New(DataTable excel, string inspecid, int startRow, List<DataRow> oldUnit)
        {
            DataTable kh = new DataTable();
            PropertyInfo[] propertys = GetAllProperty(new S_Rdfrc());
            foreach (PropertyInfo p in propertys)
            {
                kh.Columns.Add(new DataColumn(p.Name.ToUpper()));
            }
            kh.Columns.Add(new DataColumn("index")); //记录错误行号
            if (excel.Rows.Count == 0)
            {
                throw new Exception("Excel没有数据");
            }
            Dictionary<string, List<B_Unit>> temp = new Dictionary<string, List<B_Unit>>();
            CheckDatatable(excel, 1, 2, 3);
            int index = startRow + 1;
            List<string> keys = new List<string>();
            foreach (DataRow r in excel.Rows)
            {
                double _start = Convert.ToDouble(r[1]);//起点桩号
                double _end = Convert.ToDouble(r[2]);//结束桩号
                string _rdid = r[0].ToString();//路线编号
                string _dir = getDir(r[excel.Columns.Count - 1].ToString());//方向  
                //该线路该方向下的所有单元

                List<B_Unit> b_unitList = GetCacheUnit(_rdid, _dir);//GetCacheUnit(_rdid, _dir); ;// 

                string _unit = "";

                string _name = "";
                //模糊匹配单元
                //Matching(b_unitList, ref _start, ref _end, ref _unit, ref _name);
                Matching(b_unitList, ref _start, ref _end, ref _unit, ref _name);
                string _svydata = r[3].ToString();//调查日期
                //过滤重复单元
                if (!keys.Contains(_unit + "#" + _dir))
                {
                    keys.Add(_unit + "#" + _dir);
                }
                else
                {
                    continue;
                }
                string _device = r[4].ToString();//检测设备
                string _insid = inspecid;//评定ID
                string _surveyer = r[5].ToString();//检测人员
                string _sfc = r[6].ToString();//横向力系数
                string _comments = r[7].ToString();//备注
                string _importdate = DateTime.Now.ToShortDateString();//导入时间
                double version =  GetVersion(_rdid);//版本
                DataRow dr = kh.NewRow();
                dr["UNIT"] = _unit;
                dr["SVYDATA"] = _svydata;
                dr["RDWAYID"] = _rdid;
                dr["DIRECTION_DICTID"] = _dir;
                dr["HIS_VERSION"] = version;
                dr["NAME"] = _name;
                dr["DEVICE"] = _device;
                dr["INSPECID"] = _insid;
                dr["SURVEYER"] = _surveyer;
                dr["SFC"] = _sfc;
                dr["COMMENTS"] = _comments;
                dr["IMPORTDATE"] = _importdate;
                dr["index"] = index++;
               
                //检查是否有该批次的重复评定数据
                if(this.Scene.Bll.S_Inspeaccse.Exists(_unit, inspecid, "S_Rdfrc",_svydata))
                {
                    //S_Rdfrc s_rdfrc = new S_Rdfrc() {
                    //    Unit = _unit,
                    //    Svydata = DateTime.Parse( _svydata),
                    //    Inspecid = inspecid,
                    //    Name = _name,
                    //    Rdwayid = _rdid,
                    //    Direction_Dictid = int.Parse( _dir),
                    //    His_Version = version,
                    //    Device = _device,
                    //    Surveyer = _surveyer,
                    //    Sfc = Convert.ToDouble( _sfc),
                    //    Comments = _comments,
                    //    Importdate = DateTime.Parse(_importdate)
                    //};
                    oldUnit.Add(dr);
                    continue;
                } 
                kh.Rows.Add(dr);
               
            }
            return kh;
        }

        private int ImportKH(string path, string inspecid)
        {
            List<DataRow> oldUnit = new List<DataRow>();//保存重复的unit
            int startRow = 0;
            DataTable excel = Common.C_Excel.ExcelTool.GetDataTableFromExcel(path, startRow);
            DataTable entity = GetKHData_New(excel, inspecid, startRow, oldUnit);

            //TestCheckData(entity); //冲突测试

            Excel_BaseImportData exData = new Excel_BaseImportData(new S_Rdfrc());//抗滑数据
            exData.DtSource = entity;
            exData.TableName = "S_Rdfrc"; //抗滑数据
            this.Scene.Bll.Excel.ImportData(exData);
            //更改评定的路基列
            this.Scene.Bll.S_Inspeaccse.UpdateStatus(inspecid, "ISRDFRC");
            //将重复的unit保存到缓存
            if (oldUnit.Count > 0)
            {
                Common.C_Utils.MyCacheTools.SetCache("old", oldUnit, 24);//保存到缓存
            }
            return oldUnit.Count;
        }
        #endregion

        #region 平整度处理方法
        private DataTable GetPZDData_New(DataTable excel, string inspecid, int startRow, List<DataRow> oldUnit)
        {
            DataTable kh = new DataTable();
            PropertyInfo[] propertys = GetAllProperty(new S_Rdrgh());
            foreach (PropertyInfo p in propertys)
            {
                kh.Columns.Add(new DataColumn(p.Name.ToUpper()));
            }
            kh.Columns.Add(new DataColumn("index")); //记录错误行号
            if (excel.Rows.Count == 0)
            {
                throw new Exception("Excel没有数据");
            }
            Dictionary<string, List<B_Unit>> temp = new Dictionary<string, List<B_Unit>>();
            CheckDatatable(excel, 1, 2, 3);
            int index = startRow + 1;
            List<string> keys = new List<string>();
            foreach (DataRow r in excel.Rows)
            {
                double _start = Convert.ToDouble(r[1]);//起点桩号
                double _end = Convert.ToDouble(r[2]);//结束桩号
                string _rdid = r[0].ToString();//路线编号
                string _dir = getDir(r[excel.Columns.Count - 1].ToString());//方向
                //该线路该方向下的所有单元

                List<B_Unit> b_unitList = GetCacheUnit(_rdid, _dir); ;// GetCacheUnit(_rdid, _dir);

                string _unit = "";
                string _name = "";
                //模糊匹配单元
                Matching(b_unitList, ref _start, ref _end, ref _unit, ref _name);

                string _svydata = r[3].ToString();//调查日期
                //过滤重复单元
                if (!keys.Contains(_unit + "#" + _dir))
                {
                    keys.Add(_unit + "#" + _dir);
                }
                else
                {
                    continue;
                }
                string _device = r[5].ToString();//检测设备
                string _insid = inspecid;//评定ID
                string _surveyer = r[4].ToString();//检测人员
                string _iri = r[6].ToString();//横向力系数
                string _comments = r[7].ToString();//备注
                string _importdate = DateTime.Now.ToShortDateString();//导入时间
                DataRow dr = kh.NewRow();
                dr["UNIT"] = _unit;
                dr["SVYDATA"] = _svydata;
                dr["NAME"] = _name;
                dr["RDWAYID"] = _rdid;
                dr["DIRECTION_DICTID"] = _dir;
                dr["HIS_VERSION"] = GetVersion(_rdid);
                dr["DEVICE"] = _device;
                dr["INSPECID"] = _insid;
                dr["SURVEYER"] = _surveyer;
                dr["IRI"] = _iri;
                dr["COMMENTS"] = _comments;
                dr["IMPORTDATE"] = _importdate;
                dr["index"] = index++;
                
                //检查是否有该批次最新的重复评定数据
                //string oldSVYDATA = this.Scene.Bll.S_Inspeaccse.Exists(_unit, inspecid, "S_Rdrgh");// this.Scene.Bll.S_Rdrgh.Exists(_unit, inspecid);
                //检查是否有该批次的重复评定数据
                if (this.Scene.Bll.S_Inspeaccse.Exists(_unit, inspecid, "S_Rdrgh", _svydata))
                {

                    oldUnit.Add(dr);
                    continue;
                }
                kh.Rows.Add(dr);
            }
            return kh;
        }
        private int ImportPZD(string path, string inspecid)
        {
            List<DataRow> oldUnit = new List<DataRow>();//保存重复的unit
            int startRow = 0;
            DataTable excel = Common.C_Excel.ExcelTool.GetDataTableFromExcel(path, startRow);
            DataTable entity = GetPZDData_New(excel, inspecid, startRow, oldUnit);
            Excel_BaseImportData exData = new Excel_BaseImportData(new S_Rdrgh());//平整度
            exData.DtSource = entity;
            exData.TableName = "S_Rdrgh"; //平整度
            this.Scene.Bll.Excel.ImportData(exData);
            //更改评定的路基列
            this.Scene.Bll.S_Inspeaccse.UpdateStatus(inspecid, "ISRDRGH");
            //将重复的unit保存到缓存
            if (oldUnit.Count > 0)
            {
                Common.C_Utils.MyCacheTools.SetCache("old", oldUnit, 24);//保存到缓存
            }
            return oldUnit.Count;
        }
        #endregion

        #region 结构强度处理方法
        private DataTable GetQDData_New(DataTable excel, string inspecid, int startRow, List<DataRow> oldUnit)
        {
            DataTable kh = new DataTable();
            PropertyInfo[] propertys = GetAllProperty(new S_Rdpssi());
            foreach (PropertyInfo p in propertys)
            {
                kh.Columns.Add(new DataColumn(p.Name.ToUpper()));
            }
            kh.Columns.Add(new DataColumn("index")); //记录错误行号
            if (excel.Rows.Count == 0)
            {
                throw new Exception("Excel没有数据");
            }
            Dictionary<string, List<B_Unit>> temp = new Dictionary<string, List<B_Unit>>();
            CheckDatatable(excel, 1, 2, 3);
            int index = startRow + 1;
            List<string> keys = new List<string>();
            foreach (DataRow r in excel.Rows)
            {
                double _start = Convert.ToDouble(r[1]);//起点桩号
                double _end = Convert.ToDouble(r[2]);//结束桩号
                string _rdid = r[0].ToString();//路线编号
                string _dir = getDir(r[excel.Columns.Count - 1].ToString());//方向
                //该线路该方向下的所有单元

                List<B_Unit> b_unitList = GetCacheUnit(_rdid, _dir); ;// GetCacheUnit(_rdid, _dir);

                string _unit = "";
                string _name = "";
                //模糊匹配单元
                Matching(b_unitList, ref _start, ref _end, ref _unit, ref _name);

                string _PSSIDATE = r[3].ToString();//调查日期
                //过滤重复单元
                if (!keys.Contains(_unit + "#" + _dir))
                {
                    keys.Add(_unit + "#" + _dir);
                }
                else
                {
                    continue;
                }
                string _device = r[4].ToString();//检测设备
                string _insid = inspecid;//评定ID
                string _surveyer = r[5].ToString();//检测人员
                string _LFDEFL = r[6].ToString();//左弯沉
                string _RGDEFL = r[7].ToString();//右弯沉
                string _REPDEFL = r[8].ToString();//实际弯沉
                double _SSI = 0;//查找SSI
                string _degdf = GetDEGDF(_start, _end, _rdid);
                if (string.IsNullOrEmpty(_degdf))
                {
                    throw new Exception(_rdid + "路线没有找到桩号对应的设计弯沉,无法计算SSI指标,起点: " + _start + " 终点:" + _end);
                }
                _SSI = Common.C_Utils.Calc.SSI(Convert.ToDouble(_degdf), Convert.ToDouble(_REPDEFL));//得到SSI
                string _importdate = DateTime.Now.ToShortDateString();//导入时间
                DataRow dr = kh.NewRow();
                dr["UNIT"] = _unit;
                dr["SVYDATA"] = _PSSIDATE;
                dr["RDWAYID"] = _rdid;
                dr["DIRECTION_DICTID"] = _dir;
                dr["HIS_VERSION"] = GetVersion(_rdid);
                dr["NAME"] = _name;
                dr["DEVICE"] = _device;
                dr["INSPECID"] = _insid;
                dr["SURVEYER"] = _surveyer;
                dr["LFDEFL"] = _LFDEFL;
                dr["RGDEFL"] = _RGDEFL;
                dr["REPDEFL"] = _REPDEFL;
                dr["SSI"] = _SSI;
                dr["IMPORTDATE"] = _importdate;
                dr["index"] = index++;
                //kh.Rows.Add(dr);
                ////检查是否有该批次最新的重复评定数据
                //string oldSVYDATA = this.Scene.Bll.S_Inspeaccse.Exists(_unit, inspecid, "S_Rdpssi");// this.Scene.Bll.S_Rdpssi.Exists(_unit, inspecid);
                //检查是否有该批次的重复评定数据
                if (this.Scene.Bll.S_Inspeaccse.Exists(_unit, inspecid, "S_Rdpssi", _PSSIDATE))
                {

                    oldUnit.Add(dr);
                    continue;
                }
                kh.Rows.Add(dr);
            }
            return kh;
        }

        private int ImportQD(string path, string inspecid)
        {
            List<DataRow> oldUnit = new List<DataRow>();//保存重复的unit
            int startRow = 0;
            DataTable excel = Common.C_Excel.ExcelTool.GetDataTableFromExcel(path, startRow);
            DataTable entity = GetQDData_New(excel, inspecid, startRow, oldUnit);
            Excel_BaseImportData exData = new Excel_BaseImportData(new S_Rdpssi());//强度
            exData.DtSource = entity;
            exData.TableName = "S_Rdpssi"; //强度
            this.Scene.Bll.Excel.ImportData(exData);
            //更改评定的路基列
            this.Scene.Bll.S_Inspeaccse.UpdateStatus(inspecid, "ISRDPSSI");
            //将重复的unit保存到缓存
            if (oldUnit.Count > 0)
            {
                Common.C_Utils.MyCacheTools.SetCache("old", oldUnit, 24);//保存到缓存
            }
            return oldUnit.Count;
        }
        #endregion

        #region 沥青病害处理方法
        private DataTable GetLQBHData_New(DataTable excel, string inspecid, int startRow, List<DataRow> oldUnit)
        {
            DataTable kh = new DataTable();
            PropertyInfo[] propertys = GetAllProperty(new S_Pmds_Asp());
            foreach (PropertyInfo p in propertys)
            {
                kh.Columns.Add(new DataColumn(p.Name.ToUpper()));
            }
            kh.Columns.Add(new DataColumn("index")); //记录错误行号
            if (excel.Rows.Count == 0)
            {
                throw new Exception("Excel没有数据");
            }
            Dictionary<string, List<B_Unit>> temp = new Dictionary<string, List<B_Unit>>();
            CheckDatatable(excel, 4, 5, 1);
            int index = startRow + 1;
            List<string> keys = new List<string>();
            foreach (DataRow r in excel.Rows)
            {
                double _start = Convert.ToDouble(r[4]);//起点桩号
                double _end = Convert.ToDouble(r[5]);//结束桩号
                string _rdid = r[0].ToString();//路线编号
                string _dir = getDir(r[excel.Columns.Count - 1].ToString());//方向
                //该线路该方向下的所有单元

                List<B_Unit> b_unitList = GetCacheUnit(_rdid, _dir); ;// GetCacheUnit(_rdid, _dir);

                string _unit = "";

                string _name = "";
                //模糊匹配单元
                Matching(b_unitList, ref _start, ref _end, ref _unit, ref _name);

                string _SVYDATA = r[1].ToString();//调查日期
                //过滤重复单元
                if (!keys.Contains(_unit + "#" + _dir))
                {
                    keys.Add(_unit + "#" + _dir);
                }
                else
                {
                    continue;
                }
                string _insid = inspecid;//评定ID
                string _surveyer = r[2].ToString();//检测人员
                string _PMWID = r[3].ToString();//路面宽度
                string _ALGCK_L = r[6].ToString();//龟裂L
                string _ALGCK_M = r[7].ToString();//龟裂M
                string _ALGCK_H = r[8].ToString();//龟裂H
                string _BLFT_L = r[9].ToString();//块裂L
                string _BLFT_H = r[10].ToString();//块裂H
                string _LGCK_L = r[11].ToString();//纵缝L
                string _LGCK_H = r[12].ToString();//纵缝H
                string _TRSCK_L = r[13].ToString();//横缝L
                string _TRSCK_H = r[14].ToString();//横缝H
                string _PIT_L = r[15].ToString();//坑槽L
                string _PIT_H = r[16].ToString();//坑槽H
                string _LOS_L = r[17].ToString();//松散L
                string _LOS_H = r[18].ToString();//松散H
                string _SINK_L = r[19].ToString();//沉陷L
                string _SINK_H = r[20].ToString();//沉陷H
                string _PLWV_L = r[21].ToString();//车辙L
                string _PLWV_H = r[22].ToString();//车辙H
                string _RUT_L = r[23].ToString();//波浪拥包L
                string _RUT_H = r[24].ToString();//波浪拥包H
                string _BLED = r[25].ToString();//泛油
                string _REPAIR = r[26].ToString();//修补
                string _importdate = DateTime.Now.ToShortDateString();//导入时间
                DataRow dr = kh.NewRow();
                dr["UNIT"] = _unit;
                dr["SVYDATA"] = _SVYDATA;
                dr["NAME"] = _name;
                dr["RDWAYID"] = _rdid;
                dr["DIRECTION_DICTID"] = _dir;
                dr["HIS_VERSION"] = GetVersion(_rdid);
                dr["INSPECID"] = _insid;
                dr["SVYPS"] = _surveyer;
                dr["PMWID"] = _PMWID;
                dr["ALGCK_L"] = _ALGCK_L == "" ? "0" : _ALGCK_L;
                dr["ALGCK_M"] = _ALGCK_M == "" ? "0" : _ALGCK_M;
                dr["ALGCK_H"] = _ALGCK_H == "" ? "0" : _ALGCK_H;
                dr["BLFT_L"] = _BLFT_L == "" ? "0" : _BLFT_L;
                dr["BLFT_H"] = _BLFT_H == "" ? "0" : _BLFT_H;
                dr["LGCK_L"] = _LGCK_L == "" ? "0" : _LGCK_L;
                dr["LGCK_H"] = _LGCK_H == "" ? "0" : _LGCK_H;
                dr["TRSCK_L"] = _TRSCK_L == "" ? "0" : _TRSCK_L;
                dr["TRSCK_H"] = _TRSCK_H == "" ? "0" : _TRSCK_H;
                dr["PIT_L"] = _PIT_L == "" ? "0" : _PIT_L;
                dr["PIT_H"] = _PIT_H == "" ? "0" : _PIT_H;
                dr["LOS_L"] = _LOS_L == "" ? "0" : _LOS_L;
                dr["LOS_H"] = _LOS_H == "" ? "0" : _LOS_H;
                dr["SINK_L"] = _SINK_L == "" ? "0" : _SINK_L;
                dr["SINK_H"] = _SINK_H == "" ? "0" : _SINK_H;
                dr["PLWV_L"] = _PLWV_L == "" ? "0" : _PLWV_L;
                dr["PLWV_H"] = _PLWV_H == "" ? "0" : _PLWV_H;
                dr["RUT_L"] = _RUT_L == "" ? "0" : _RUT_L;
                dr["RUT_H"] = _RUT_H == "" ? "0" : _RUT_H;
                dr["BLED"] = _BLED == "" ? "0" : _BLED;
                dr["REPAIR"] = _REPAIR == "" ? "0" : _REPAIR;

                dr["IMPORTDATE"] = _importdate;
                dr["index"] = index++;
                //检查是否有该批次的重复评定数据
                if (this.Scene.Bll.S_Inspeaccse.Exists(_unit, inspecid, "S_Pmds_Asp", _SVYDATA))
                {

                    oldUnit.Add(dr);
                    continue;
                }
                kh.Rows.Add(dr);
            }
            return kh;
        }

        private int ImportLQBH(string path, string inspecid)
        {
            List<DataRow> oldUnit = new List<DataRow>();//保存重复的unit
            int startRow = 2;
            DataTable excel = Common.C_Excel.ExcelTool.GetDataTableFromExcel(path, startRow);
            DataTable entity = GetLQBHData_New(excel, inspecid, startRow, oldUnit);
            Excel_BaseImportData exData = new Excel_BaseImportData(new S_Pmds_Asp());//沥青病害
            exData.DtSource = entity;
            exData.TableName = "S_Pmds_Asp"; //沥青病害
            this.Scene.Bll.Excel.ImportData(exData);
            //更改评定的路基列
            this.Scene.Bll.S_Inspeaccse.UpdateStatus(inspecid, "ISASPHALT");
            //将重复的unit保存到缓存
            if (oldUnit.Count > 0)
            {
                Common.C_Utils.MyCacheTools.SetCache("old", oldUnit, 24);//保存到缓存
            }
            return oldUnit.Count;
        }
        #endregion

        #region 砂石病害处理方法
        private DataTable GetSSBHData_New(DataTable excel, string inspecid, int startRow, List<DataRow> oldUnit)
        {
            DataTable kh = new DataTable();
            PropertyInfo[] propertys = GetAllProperty(new S_Pmds_S());
            foreach (PropertyInfo p in propertys)
            {
                kh.Columns.Add(new DataColumn(p.Name.ToUpper()));
            }
            kh.Columns.Add(new DataColumn("index")); //记录错误行号
            if (excel.Rows.Count == 0)
            {
                throw new Exception("Excel没有数据");
            }
            Dictionary<string, List<B_Unit>> temp = new Dictionary<string, List<B_Unit>>();
            CheckDatatable(excel, 4, 5, 3);
            int index = startRow + 1;
            List<string> keys = new List<string>();
            foreach (DataRow r in excel.Rows)
            {
                double _start = Convert.ToDouble(r[4]);//起点桩号
                double _end = Convert.ToDouble(r[5]);//结束桩号
                string _rdid = r[0].ToString();//路线编号
                string _dir = getDir(r[excel.Columns.Count - 1].ToString());//方向
                //该线路该方向下的所有单元

                List<B_Unit> b_unitList = GetCacheUnit(_rdid, _dir);

                string _unit = "";
                string _name = "";
                //模糊匹配单元
                Matching(b_unitList, ref _start, ref _end, ref _unit, ref _name);


                string _SVYDATA = r[1].ToString();//调查日期
                //过滤重复单元
                if (!keys.Contains(_unit + "#" + _dir))
                {
                    keys.Add(_unit + "#" + _dir);
                }
                else
                {
                    continue;
                }
                string _insid = inspecid;//评定ID
                string _surveyer = r[2].ToString();//检测人员
                string _PMWID = r[3].ToString();//路面宽度

                string _RDCBDC = r[6].ToString();//路拱不适
                string _SINK = r[7].ToString();//沉陷
                string _PLWBD = r[8].ToString();//波浪搓板

                string _RUT = r[9].ToString();//车辙
                string _PIT = r[10].ToString();//坑槽
                string _BRFD = r[11].ToString();//露骨


                string _importdate = DateTime.Now.ToShortDateString();//导入时间
                DataRow dr = kh.NewRow();
                dr["UNIT"] = _unit;
                dr["SVYDATA"] = _SVYDATA;
                dr["RDWAYID"] = _rdid;
                dr["DIRECTION_DICTID"] = _dir;
                dr["HIS_VERSION"] = GetVersion(_rdid);
                dr["INSPECID"] = _insid;
                dr["NAME"] = _name;
                dr["SVYPS"] = _surveyer;
                dr["PMWID"] = _PMWID;
                dr["RDCBDC"] = _RDCBDC == "" ? "0" : _RDCBDC;
                dr["SINK"] = _SINK == "" ? "0" : _SINK;
                dr["PLWBD"] = _PLWBD == "" ? "0" : _PLWBD;
                dr["RUT"] = _RUT == "" ? "0" : _RUT;
                dr["BRFD"] = _BRFD == "" ? "0" : _BRFD;

                dr["IMPORTDATE"] = _importdate;
                dr["index"] = index++;
                //检查是否有该批次的重复评定数据
                if (this.Scene.Bll.S_Inspeaccse.Exists(_unit, inspecid, "S_Pmds_S", _SVYDATA))
                {

                    oldUnit.Add(dr);
                    continue;
                }
                kh.Rows.Add(dr);
            }
            return kh;
        }

        private int ImportSSBH(string path, string inspecid)
        {
            List<DataRow> oldUnit = new List<DataRow>();//保存重复的unit
            int startRow = 0;
            DataTable excel = Common.C_Excel.ExcelTool.GetDataTableFromExcel(path, startRow);
            DataTable entity = GetSSBHData_New(excel, inspecid, startRow, oldUnit);
            Excel_BaseImportData exData = new Excel_BaseImportData(new S_Pmds_S());//砂石病害
            exData.DtSource = entity;
            exData.TableName = "S_Pmds_S"; //砂石病害
            this.Scene.Bll.Excel.ImportData(exData);
            //更改评定的路基列
            this.Scene.Bll.S_Inspeaccse.UpdateStatus(inspecid, "ISGRAVEL");
            //将重复的unit保存到缓存
            if (oldUnit.Count > 0)
            {
                Common.C_Utils.MyCacheTools.SetCache("old", oldUnit, 24);//保存到缓存
            }
            return oldUnit.Count;
        }
        #endregion

        #region 水泥病害处理方法
        private DataTable GetSNBHData_New(DataTable excel, string inspecid, int startRow, List<DataRow> oldUnit)
        {
            DataTable kh = new DataTable();
            PropertyInfo[] propertys = GetAllProperty(new S_Pmds_Cem());
            foreach (PropertyInfo p in propertys)
            {
                kh.Columns.Add(new DataColumn(p.Name.ToUpper()));
            }
            kh.Columns.Add(new DataColumn("index")); //记录错误行号
            if (excel.Rows.Count == 0)
            {
                throw new Exception("Excel没有数据");
            }
            Dictionary<string, List<B_Unit>> temp = new Dictionary<string, List<B_Unit>>();
            CheckDatatable(excel, 4, 5, 1);
            int index = startRow + 1;
            List<string> keys = new List<string>();
            foreach (DataRow r in excel.Rows)
            {
                double _start = Convert.ToDouble(r[4]);//起点桩号
                double _end = Convert.ToDouble(r[5]);//结束桩号
                string _rdid = r[0].ToString();//路线编号
                string _dir = getDir(r[excel.Columns.Count - 1].ToString());//方向
                //该线路该方向下的所有单元

                List<B_Unit> b_unitList = GetCacheUnit(_rdid, _dir);

                string _unit = "";
                string _name = "";
                //模糊匹配单元
                Matching(b_unitList, ref _start, ref _end, ref _unit, ref _name);

                string _SVYDATA = r[3].ToString();//调查日期
                //过滤重复单元
                if (!keys.Contains(_unit + "#" + _dir))
                {
                    keys.Add(_unit + "#" + _dir);
                }
                else
                {
                    continue;
                }
                string _insid = inspecid;//评定ID
                string _surveyer = r[1].ToString();//检测人员
                string _PMWID = r[2].ToString();//路面宽度

                string _CRSLB_L = r[6].ToString();//破碎板L
                string _CRSLB_H = r[7].ToString();//破碎板H
                string _CRACK_L = r[8].ToString();//裂缝l
                string _CRACK_M = r[9].ToString();//裂缝m
                string _CRACK_H = r[10].ToString();//裂缝h
                string _PLCNCK_L = r[11].ToString();//板角裂缝l
                string _PLCNCK_M = r[12].ToString();//板角裂缝m
                string _PLCNCK_H = r[13].ToString();//板角裂缝h
                string _STGR_L = r[14].ToString();//错台l
                string _STGR_H = r[15].ToString();//错台h
                string _PUMP = r[16].ToString();//唧泥
                string _CNSPL_L = r[17].ToString();//边角剥落l
                string _CNSPL_M = r[18].ToString();//边角剥落m
                string _CNSPL_H = r[19].ToString();//边角剥落h
                string _JNSTDG_L = r[20].ToString();//接缝料l
                string _JNSTDG_H = r[21].ToString();//接缝料h

                string _PTHL = r[22].ToString();//坑洞
                string _HUHUP = r[23].ToString();//拱起
                string _REPAIR = r[24].ToString();//修补


                string _importdate = DateTime.Now.ToShortDateString();//导入时间
                DataRow dr = kh.NewRow();
                dr["UNIT"] = _unit;
                dr["SVYDATA"] = _SVYDATA;
                dr["RDWAYID"] = _rdid;
                dr["DIRECTION_DICTID"] = _dir;
                dr["HIS_VERSION"] = GetVersion(_rdid);
                dr["NAME"] = _name;
                dr["INSPECID"] = _insid;
                dr["SVYPS"] = _surveyer;
                dr["PMWID"] = _PMWID;
                dr["CRSLB_L"] = _CRSLB_L == "" ? "0" : _CRSLB_L;
                dr["CRSLB_H"] = _CRSLB_H == "" ? "0" : _CRSLB_H;
                dr["CRACK_L"] = _CRACK_L == "" ? "0" : _CRACK_L;
                dr["CRACK_M"] = _CRACK_M == "" ? "0" : _CRACK_M;
                dr["CRACK_H"] = _CRACK_H == "" ? "0" : _CRACK_H;
                dr["PLCNCK_L"] = _PLCNCK_L == "" ? "0" : _PLCNCK_L;
                dr["PLCNCK_M"] = _PLCNCK_M == "" ? "0" : _PLCNCK_M;
                dr["PLCNCK_H"] = _PLCNCK_H == "" ? "0" : _PLCNCK_H;

                dr["STGR_L"] = _STGR_L == "" ? "0" : _STGR_L;
                dr["STGR_H"] = _STGR_H == "" ? "0" : _STGR_H;
                dr["PUMP"] = _PUMP == "" ? "0" : _PUMP;
                dr["CNSPL_L"] = _CNSPL_L == "" ? "0" : _CNSPL_L;
                dr["CNSPL_M"] = _CNSPL_M == "" ? "0" : _CNSPL_M;
                dr["CNSPL_H"] = _CNSPL_H == "" ? "0" : _CNSPL_H;
                dr["JNSTDG_L"] = _JNSTDG_L == "" ? "0" : _JNSTDG_L;
                dr["JNSTDG_H"] = _JNSTDG_H == "" ? "0" : _JNSTDG_H;
                dr["PTHL"] = _PTHL == "" ? "0" : _PTHL;
                dr["HUHUP"] = _HUHUP == "" ? "0" : _HUHUP;
                dr["REPAIR"] = _REPAIR == "" ? "0" : _REPAIR;
                dr["IMPORTDATE"] = _importdate;
                dr["index"] = index++;
                //检查是否有该批次的重复评定数据
                if (this.Scene.Bll.S_Inspeaccse.Exists(_unit, inspecid, "S_Pmds_Cem", _SVYDATA))
                {

                    oldUnit.Add(dr);
                    continue;
                }
                kh.Rows.Add(dr);
            }
            return kh;
        }

        private int ImportSNBH(string path, string inspecid)
        {
            List<DataRow> oldUnit = new List<DataRow>();//保存重复的unit
            int startRow = 0;
            DataTable excel = Common.C_Excel.ExcelTool.GetDataTableFromExcel(path, startRow);
            DataTable entity = GetSNBHData_New(excel, inspecid, startRow, oldUnit);
            Excel_BaseImportData exData = new Excel_BaseImportData(new S_Pmds_Cem());//水泥病害
            exData.DtSource = entity;
            exData.TableName = "S_Pmds_Cem"; //水泥病害
            this.Scene.Bll.Excel.ImportData(exData);
            //更改评定的路基列
            this.Scene.Bll.S_Inspeaccse.UpdateStatus(inspecid, "ISCEMENT");
            //将重复的unit保存到缓存
            if (oldUnit.Count > 0)
            {
                Common.C_Utils.MyCacheTools.SetCache("old", oldUnit, 24);//保存到缓存
            }
            return oldUnit.Count;
        }
        #endregion

        #endregion

        #region 数据缓存和字典
        private List<B_Unit> GetCacheUnit(string rdid, string dir)
        {
            if (!Common.C_Utils.MyCacheTools.IsCacheExist("unit_" + rdid + "_" + dir))
            {
                List<B_Unit> lst = this.Scene.Bll.B_Unit.GetUnitList<B_Unit>(dir, rdid);
                if (lst.Count == 0) { throw new Exception("系统没有为路线" + rdid + "在该方向上划分路段"); }
                Common.C_Utils.MyCacheTools.SetCache("unit_" + rdid + "_" + dir, lst, 24);//保存到缓存
                return lst;
            }
            else
            {
                return Common.C_Utils.MyCacheTools.GetCache("unit_" + rdid + "_" + dir) as List<B_Unit>;
            }
        }

        private string GetDEGDF(double start, double end, string rdid)
        {
            IEnumerable<B_Pmstc> pmstcs;
            if (!Common.C_Utils.MyCacheTools.IsCacheExist("pmstc_" + rdid ))
            {
                pmstcs = this.Scene.Bll.B_Pmstc.GetPmstc<B_Pmstc>(rdid);//查找设计弯沉对象
                Common.C_Utils.MyCacheTools.SetCache("pmstc_" + rdid, pmstcs, 24);//保存到缓存
            }
            else
            {
                pmstcs = Common.C_Utils.MyCacheTools.GetCache("pmstc_" + rdid) as IEnumerable<B_Pmstc>;
            }
            if(pmstcs.Any<B_Pmstc>())
            {
                foreach(B_Pmstc p in pmstcs)
                {
                    if(p.Beginmp<= start && p.Endmp>= end)
                    {
                        return p.Degdf.ToString();
                    }
                }
                return "";
            }
            return "";
        }
        private double GetVersion(string rdid)
        {
            if (!Common.C_Utils.MyCacheTools.IsCacheExist("version_" + rdid))
            {
                double lst = this.Scene.Bll.B_Roadway.GetNewHistoryVersion(rdid, false);
                Common.C_Utils.MyCacheTools.SetCache("version_" + rdid, lst, 24);//保存到缓存
                return lst;
            }
            else
            {
                return (double)Common.C_Utils.MyCacheTools.GetCache("version_" + rdid);
            }
        }

        private string getDir(string dir)
        {
            string _dir = "";
            if (Common.C_Enum.DirectionEnum.All13.GetEnumDescription() == dir)
            {
                _dir = Common.C_Enum.DirectionEnum.All13.GetEnumValue().ToString();
            }
            else if (Common.C_Enum.DirectionEnum.Up11.GetEnumDescription() == dir)
            {
                _dir = Common.C_Enum.DirectionEnum.Up11.GetEnumValue().ToString();
            }
            else if (Common.C_Enum.DirectionEnum.Down12.GetEnumDescription() == dir)
            {
                _dir = Common.C_Enum.DirectionEnum.Down12.GetEnumValue().ToString();
            }
            return _dir;
        }

        #endregion
    }


    public class RdClass
    {
        public string Name { get; set; }
        public UpClass Up { get; set; }
        public DownClass Down { get; set; }
        public AllClass All { get; set; }
    }

    public class UpClass
    {
        public DateTime Time { get; set; }
        public string Max { get; set; }
        public string Min { get; set; }
    }

    public class DownClass
    {
        public DateTime Time { get; set; }
        public string Max { get; set; }
        public string Min { get; set; }
    }

    public class AllClass
    {
        public DateTime Time { get; set; }
        public string Max { get; set; }
        public string Min { get; set; }
    }
}